﻿using System;
using System.Activities;
using System.Collections.Generic;
using System.Data.Objects.DataClasses;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Wicresoft.AppFlow.Flows;
using AppLab.Data.Models;

namespace Wicresoft.AppFlow.Activities
{
    public sealed class Test : StateActivity<FlowState>
    {
        protected override string BookmarkName
        {
            get { return FlowState.PendingTest.ToString(); }
        }

        protected override FlowState ResumeBookmark(NativeActivityContext context, Bookmark bookmark, object value)
        {
            var e = value as tysx_TestTask;
            Debug.Assert(e != null, "Entity object [tysx_TestTask] cannot be null");

            using (var dc = PMSEntities.Create())
            {
                var flow = dc.tysx_AppFlow.First(p => p.FlowID == context.WorkflowInstanceId);

                //添加tysx_TestTask表中元素
                var task = dc.tysx_TestTask.First(p => p.TestTaskID == flow.tysx_Submit.tysx_Review.TestTaskID);
                task.TestTypeID = e.TestTypeID;
                task.EndDate = e.EndDate;
                task.TestResultID = e.TestResultID;
                task.TestReportName = e.TestReportName;
                task.TestReport = e.TestReport;
                dc.SaveChanges();

                var submit = dc.tysx_Submit.First(p => p.SubmitID == flow.SubmitID);
                //submit.tysx_Review.TestTaskID = e.TestTaskID;
                flow.StateID = e.TestResultID;
                dc.SaveChanges();
            }

            return (FlowState)e.TestResultID;
        }
    }
}
